// Application hooks that run for every service
const logger = require('./hooks/logger');
const errors = require('@feathersjs/errors')

module.exports = {
  before: {
    all: [ logger(), d => {
      if (!d.params.inside) {
        const error = new errors.BadRequest('非法请求', {
          code: 10004
        })
        return Promise.reject(error)
      }
    } ],
    find: [ d=> {
      var get = d.params.query
      if (get && !get.del) get.del = false
      // 删除空白参数
      for(var i in get) {
        if (get[i] === '') delete get[i]
      }
    }],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [ logger() ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [ logger() ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};
